<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class SetupOrdersTable extends Migration {

	/**
	 * 订单表
	 *
	 * @return void
	 */
	public function up()
	{
        ///
        Schema::create('orders', function ($table) {
            $table->increments('id');
            $table->integer('member_id')->unsigned()->default(0)->comment('会员ID');
            $table->smallInteger('status')->default(0)->comment('状态：0:已下单，1:已打票，2:已结算');
            $table->decimal('total_price',6,2)->default(0)->comment('总价');
            $table->timestamp('send_meal_time')->default(0)->comment('送餐时间');
            $table->timestamp('get_meal_time')->default(0)->comment('取餐时间');
            $table->timestamps();
            $table->foreign('member_id')->references('id')->on('members');

            $table->index('member_id');

        });
        //
        Schema::create('order_foods', function ($table) {
            $table->increments('id');
            $table->integer('order_id')->unsigned()->default(0)->comment('订单ID');

            $table->string('name',50)->nullable();
            $table->boolean('is_package')->default(false)->comment('是否为套餐');
            $table->decimal('original_price',6,2)->default(0)->comment('原价');
            $table->decimal('price', 6, 2)->default(0)->comment('现价');
            $table->integer('count')->unsigned()->default(0)->comment('数量');
            $table->text('description')->comment('描述');
            $table->timestamps();
            $table->foreign('order_id')->references('id')->on('orders');

            $table->index('order_id');
            $table->index('original_price');
            $table->index('price');
            $table->index('count');

        });

	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{

        //
        Schema::table('order_foods', function(Blueprint $table) {
            $table->dropForeign('order_foods_order_id_foreign');
        });
        Schema::drop('order_foods');

        Schema::table('orders', function(Blueprint $table) {
            $table->dropForeign('baskets_member_id_foreign');
        });
        Schema::drop('orders');
	}

}
